1634A Reverse and Concatenate codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
int chech_pali(string s)
{
int l,r;
l=0;
r=s.size()-1;
while(l<r)
{
if(s[l]!=s[r]) return 0;
l++;
r--;
}
return 1;
}
main()
{
int t,n,k;
cin>>t;
while(t--)
{
string s;
cin>>n>>k;
cin>>s;
if(k==0) cout<<"1"<<endl;
else
{
int c=chech_pali(s);
if(c) cout<<"1"<<endl;
else cout<<"2"<<endl;
}
}
return 0;
}
0 Comments